home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_6.zip / M.C < prev    next >
C/C++ Source or Header  |  1993-09-06  |  4KB  |  158 lines

  1. #include <malloc.h>
  2. #include <fcntl.h>
  3. #include <sys\types.h>
  4. #include <sys\stat.h>
  5. #include <io.h>
  6. #include <dos.h>
  7. #include <bios.h>
  8. #include <errno.h>
  9. #include <stdio.h>
  10. #include <stddef.h>
  11. #include <conio.h>
  12. #include <direct.h>
  13. #include <process.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. typedef struct {
  18.     short x;
  19.     short y;
  20.     short status;
  21.     } AVL_MOUSE, *AVL_MOUSE_PTR;
  22.  
  23. /************************************************************************/
  24. /***   Inicializa o Mouse no Video                                    ***/
  25. /*                                                                      */
  26. void AVL_MOUSE_INIT()
  27. {
  28.     union REGS inreg, outreg;
  29.     inreg.x.ax = 0;
  30.     int86(0x33, &inreg, &outreg);
  31.     inreg.x.ax = 1;
  32.     int86(0x33, &inreg, &outreg);
  33. }
  34.  
  35. void AVL_MOUSE_ON()
  36. {
  37.     union REGS inreg, outreg;
  38.     inreg.x.ax = 1;
  39.     int86(0x33, &inreg, &outreg);
  40. }
  41.  
  42. void AVL_MOUSE_OFF()
  43. {
  44.     union REGS inreg, outreg;
  45.     inreg.x.ax = 2;
  46.     int86(0x33, &inreg, &outreg);
  47. }
  48.  
  49. void AVL_MOUSE_SET(int x, int y)
  50. {
  51.     union REGS inreg, outreg;
  52.     inreg.x.ax = 4;
  53.     inreg.x.cx = x;
  54.     inreg.x.dx = y;
  55.     int86(0x33, &inreg, &outreg);
  56. }
  57.  
  58. /************************************************************************/
  59. /***   Fornece o Status do Mouse - Posicao, Botao Precionado.            ***/
  60. /**    Botoes: 0 - esquerda                                            **/
  61. /*             1 - direita          Obs.: Definir estrutura de volta    */
  62. /*             2 - meio                   fora do programa.  xmouse     */
  63. /*                                                           ymouse     */
  64. /*    Retorna:  1 - se botao pressionado                                */
  65. /*              0 - caso contrario ou se nro. do botao for invalido     */
  66. /*                                                                      */
  67. AVL_MOUSE AVL_MOUSE_STATUS()
  68. {
  69.     union REGS inreg, outreg;
  70.     static AVL_MOUSE m;
  71.     short i;
  72.  
  73.     inreg.x.ax = 3;
  74.     inreg.x.bx = 0;
  75.  
  76.     int86(0x33, &inreg, &outreg);
  77.  
  78.     m.x = outreg.x.dx;
  79.     m.y = outreg.x.cx;
  80.     m.x = m.x / 8 + 1;
  81.     m.y = m.y / 8 + 1;
  82.     m.status = outreg.x.bx;
  83.  
  84.     return(m);
  85. }
  86.  
  87. void AVL_WVIDEO(unsigned char x, unsigned char a, short *c);
  88. #define avl_video_base_address  0xB8000
  89. #define AVL_MAP(r,c)  ((short *) (avl_video_base_address + (r - 1) * 160 + (c - 1) * 2))
  90. #define AVL_PUT(ch,r,c,bk,cor) *AVL_MAP(r,c) = ((char) ch) | ((short) (((bk << 4) | cor) << 8))
  91. #define AVL_ATT(r,c) ((char) (*(AVL_MAP(r,c)) >> 8))
  92. #define AVL_CH(r,c)  ((char) *AVL_MAP(r,c))
  93.  
  94.  
  95. static AVL_MOUSE m1;
  96.  
  97. AVL_MOUSE AVL_MOUSE_SELECT(int x1, int y1, int x2, int y2, int *row)
  98. {
  99.     static AVL_MOUSE m;
  100.     short i;
  101.     short c;
  102.     char ch;
  103.     char s[20];
  104.     m = AVL_MOUSE_STATUS();
  105.     if (m1.x == 0 && m1.y == 0)
  106.         m1 = m;
  107.     sprintf(s,"%2d %2d", m.x, m.y);
  108.     for(i = 0; i < strlen(s); ++i)
  109.         AVL_WVIDEO(s[i],(unsigned char) (0 << 4 | 3), AVL_MAP(1,73+i));
  110.     if (m.x >= x1 && m.x <= x2 && m.y >= y1 && m.y <= y2) {
  111.         for(i=y1; i <= y2; ++i)  {
  112.             c = *AVL_MAP(m.x,i);
  113.             ch = c;
  114.             AVL_WVIDEO(c,(unsigned char) (0 << 4 | 4), AVL_MAP(m.x,i));
  115.             }
  116.         if (m1.x != m.x)  {
  117.             for(i=y1; i <= y2; ++i)  {
  118.                 c = *AVL_MAP(m1.x,i);
  119.                 ch = c;
  120.                 AVL_WVIDEO(c,(unsigned char) (0 << 4 | 15), AVL_MAP(m1.x,i));
  121.                 }
  122.             m1 = m;
  123.             }
  124.         }
  125.     if (m.status == 1)  {
  126.         AVL_MOUSE_OFF();
  127.         exit(1);
  128.         }
  129.     return m;
  130. }
  131.  
  132.     main()
  133. {
  134.     int i;
  135.     AVL_MOUSE m;
  136.     m1.x = m1.y = 0;
  137.  
  138.     AVL_MOUSE_INIT();
  139.     AVL_MOUSE_ON();
  140.  
  141.     while ( 1 )  {
  142. /*        m = AVL_MOUSE_STATUS();
  143.         if (kbhit())  {
  144.             printf("AVL_MOUSE_STATUS=%d x=%2d y=%2d\n"
  145.                 , m.status, m.x, m.y);
  146.             i = getch();
  147.             if (i == 0) i = getch();
  148.             }
  149. */
  150.         m = AVL_MOUSE_SELECT(2,2,15,20);
  151. /*        m = AVL_MOUSE_STATUS();
  152.         if (m.status == 1) 
  153.             break; 
  154. */
  155.         }
  156.     AVL_MOUSE_OFF();
  157. }
  158.